#ifndef ORTHO_H
#define ORTHO_H

#include <QFile>
#include <QDir>
#include <QHash>
#include <QStringList>
#include <QDebug>
#include <QTextStream>
#include <QTime>
#include <QObject>

#include "config.h"

class Ortho : public QObject
{
		Q_OBJECT

	private:

		QHash<QString, QStringList> m_dics;

		QString m_currentLanguage;

		static inline int min2 (int a, int b)
		{
			return (a < b) ? a : b;
		}

		static inline int min3 (int a, int b, int c)
		{
			return min2 (a, min2 (b, c));
		}

		static inline bool isAConsonant (const QChar& car)
		{
			return QString ("BCDFGHJKLMNPQRSTVWXZ").contains (car, Qt::CaseInsensitive);
		}

		static inline bool containsOnlyConsonants (QString& word)
		{

			foreach (const QChar& car, word)
			{
				if (! isAConsonant (car)) return false;
			}

			return true;
		}

		static inline bool isOnlyDigits (const QString& word)
		{
			bool ok;

			word.toInt (&ok);
			return ok;
		}

		QStringList allWords ();

		static inline int dlDistance (const QString& str1, const QString& str2, const int limit = 100000);

		void loadDics (QString lang = "");

		bool dicContains (QString word)
		{
			return allWords ().contains (word, Qt::CaseInsensitive);
		}


	public:
		explicit Ortho (QObject* parent = 0);


		bool isMispelled (QString word)
		{
			return ! isOnlyDigits (word) && ! dicContains (word);
		}

		QStringList unknownWords (QString text);

		QStringList suggests (QString word);

		QStringList languages ();
		const QString& currentLanguage ();

	public slots:
		void setCurrentLanguage (QString lang);
};

//-------------------------------------------------------------------------------------------------------




#endif // ORTHO_H
